package com.ellecity06.cwhiskymall.ui.service_setting

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.ellecity06.common.base.BaseMvvmActivity
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.common.widgets.dialog.showAlert
import com.ellecity06.cwhiskymall.databinding.ActivityServiceSettingBinding
import com.ellecity06.cwhiskymall.storage.AppStorage
import com.ellecity06.cwhiskymall.utils.AppTools

/**
 * @author ellecity06
 * @time 2024/11/14 10:32
 * @des
 */
class ServiceSettingActivity : BaseMvvmActivity<ActivityServiceSettingBinding, BaseViewModel>() {
    private val adapter :ServiceSettingAdapter by lazy { ServiceSettingAdapter() }
    private val serviceList: MutableList<ServiceModel> by lazy {
        mutableListOf(
            ServiceModel(
                name = "童文辉本地环境",
                apiUrl = "http://192.168.0.77:9925/",
                webUrl = "http://192.168.0.52:8080/#/",
                ipWebUrl = "http://192.168.0.144:3000/#/",
                caewapUrl = "https://caewaph5-uat.jiudageapp.com/#/",
                key = "test-wenhui"
            ),
            ServiceModel(
                name = "沈少刚本地环境",
                apiUrl = "http://192.168.0.143:9925/",
                webUrl = "http://192.168.0.52:8080/#/",
                ipWebUrl = "http://192.168.0.144:3000/#/",
                caewapUrl = "https://caewaph5-uat.jiudageapp.com/#/",
                key = "test-shaogang"
            ),
            ServiceModel(
                name = "刘长林本地环境",
                apiUrl = "http://192.168.0.68:9925/",
                webUrl = "http://192.168.0.52:8080/#/",
                ipWebUrl = "http://192.168.0.144:3000/#/",
                caewapUrl = "https://caewaph5-uat.jiudageapp.com/#/",
                key = "test-changlin"
            ),
            ServiceModel(
                name = "测试环境",
                apiUrl = "http://gw-t.jiudageapp.com/",
                webUrl = "https://mallapps-t.jiudageapp.com/#/",
                ipWebUrl = "https://reg-t.jiudageapp.com/#/",
                caewapUrl = "https://caewaph5-uat.jiudageapp.com/#/",
                key = "test-online"
            ),
//            ServiceModel(
//                name = "审核用的环境",
//                apiUrl = "https://gw-payexamin.jiudageapp.com/",
//                webUrl = "https://mallapps-t.jiudageapp.com/#/",
//                ipWebUrl = "https://reg-t.jiudageapp.com/#/",
//                caewapUrl = "https://caewaph5-uat.jiudageapp.com/",
//                key = "test-payexamin"
//            ),
            ServiceModel(
                name = "生产线上",
                apiUrl = "https://gw.jiudageapp.com/",
                webUrl = "https://mallapps.jiudageapp.com/#/",
                ipWebUrl = "https://reg.jiudageapp.com/#/",
                caewapUrl = "https://caewaph5.jiudageapp.com/#/",
                key = "online-release"
            )
        )
    }

    override fun inflateBinding(): ActivityServiceSettingBinding {
        return ActivityServiceSettingBinding.inflate(layoutInflater)
    }

    override fun initialize(savedInstanceState: Bundle?) {
        title = "环境切换"
        binding.rv.layoutManager = LinearLayoutManager(this)
        binding.rv.adapter = adapter
        adapter.submitList(serviceList)
        adapter.setOnItemClickListener { _, _, position ->
            val item= adapter.getItem(position)
            showAlert (content = "确定要切换到[${item?.name}] 吗？"){
                AppStorage.serviceKey = item?.key
                AppStorage.serviceConfig = item
                AppTools.restartApplication()
            }
        }
    }
}